import { Injectable } from '@angular/core';
import { LoginInfoService } from './login-info.service';
import { HttpService } from './http.service';

@Injectable({
  providedIn: 'root'
})
export class UpphotoService {
     
  constructor(
    public LoginInfoService: LoginInfoService,
    public HttpService: HttpService,
  ) {}
  public imgUpdata:any //返回的图片

  /***
   * @param info 上传路径
   * @type
   */
  Uploading(info:any,type?){
    let arr = []
    arr.push(info)
    let that = this;
    return new Promise<Array<object>>(function(resolve,reject){
      let p = {
        files:arr,
        idCard:'111'
      }
      that.HttpService.upImg(p).then(res=>{
        if(res['code']==200){
         if(!!!type){
           console.log("----------e.filePath------------")
          res['item'].forEach(e => {
            e.filePath = that.HttpService.upImgurl() + e.filePath
          });
         }
          resolve(res['item'])
        }else{
          alert(res['msg'])
        }
      })
    })
  }

  UploadingHead(info:any,type?){
    let arr = []
    arr.push(info)
    let that = this;
    return new Promise<Array<object>>(function(resolve,reject){
      let p = {
        files:arr,
        idCard:'111'
      }
      that.HttpService.upImg(p).then(res=>{
        if(res['code']==200){
         if(!!!type){
           console.log("----------e.filePath------------")
          res['item'].forEach(e => {
            e.filePath = e.filePath
          });
         }
          resolve(res['item'])
        }else{
          alert(res['msg'])
        }
      })
    })
  }
  
}
